<template>
  <div class="app-container">
    <el-table
      v-loading="loading"
      :data="otherCertificatesList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="姓名" align="center" prop="basicInfoId" />
      <el-table-column label="证书" align="center" prop="certificateName" />
      <el-table-column
        label="时间"
        align="center"
        prop="timeAwarded"
        width="130"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.timeAwarded, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="级别" align="center" prop="level" />
      <el-table-column label="专业" align="center" prop="major" />
      <el-table-column
        label="当时工作单位"
        align="center"
        prop="thenWorkplace"
        width="140"
      />
      <el-table-column
        label="证书授予单位"
        align="center"
        prop="certificateIssuer"
      />
      <el-table-column label="证书PDF件" align="center" prop="certificatePdf" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['profession:otherCertificates:edit']"
            >修改</el-button
          >
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['profession:otherCertificates:remove']"
            >删除</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  listOtherCertificates,
  getOtherCertificates,
  delOtherCertificates,
  addOtherCertificates,
  updateOtherCertificates,
} from "@/api/profession/otherCertificates";

export default {
  name: "OtherCertificatesQuery",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 其他证书信息表格数据
      otherCertificatesList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        basicInfoId: null,
        certificateName: null,
        timeAwarded: null,
        level: null,
        major: null,
        thenWorkplace: null,
        certificateIssuer: null,
        certificatePdf: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        basicInfoId: [
          { required: true, message: "基本信息ID不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询其他证书信息列表 */
    getList() {
      this.loading = true;
      listOtherCertificates(this.queryParams).then((response) => {
        this.otherCertificatesList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        basicInfoId: null,
        certificateName: null,
        timeAwarded: null,
        level: null,
        major: null,
        thenWorkplace: null,
        certificateIssuer: null,
        certificatePdf: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加其他证书信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getOtherCertificates(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改其他证书信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateOtherCertificates(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOtherCertificates(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除其他证书信息编号为"' + ids + '"的数据项？')
        .then(function () {
          return delOtherCertificates(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "profession/otherCertificates/export",
        {
          ...this.queryParams,
        },
        `otherCertificates_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
